package cn.seven.index;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jfinal.aop.Enhancer;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import cn.seven.Sky;

/**
 * create by 张天笑, 2017/11/7 12:42
 */
@Controller
@RequestMapping("/")
public class IndexController {
    private final Logger logger = Logger.getLogger(IndexController.class);

    IndexService isv = Enhancer.enhance(IndexService.class);

    @RequestMapping("/")
    public String index(HttpSession session,String sb) throws Exception {
        logger.info("一行白鹭上青天");
        logger.error("ERROR-------------------------------");
        System.out.println(sb);
        //session.setAttribute("ps", Product.dao.find("select * from t_product where 1=?", 1));
        //session.setAttribute("title", "mmp");
        return "index";
    }
    
    @RequestMapping("/users")
    @ResponseBody
    public Ret users(){
        List<Record> users = Db.find("select * from user");
		return Ret.ok("users", users);
    }

    @RequestMapping("/errorTest/")
    @ResponseBody
    public Sky<?> errorTest() throws Exception {
        throw new Exception("主动报错ing");
    }


    @RequestMapping("/tx/")
    @ResponseBody
    public Sky tx() {
        isv.delUser();
        return new Sky(1, "添加成功");
    }

}
